package com.wuhao.shootclient.util;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

public class ImageConverter {
    private static final int STATIC_TARGET_RADIUS = 104;

    /**
     * 将实际胸环靶图上的坐标点转换为模拟静态胸环靶图上的坐标点并标注
     */
    public static Bitmap convertToStaticTarget(
            Bitmap bitmap,
            int actualRadius,
            int relativeX,
            int relativeY,
            boolean isLastPoint
    ) {
        // 计算比例因子
        double scaleFactor = (double) STATIC_TARGET_RADIUS / actualRadius;
        // 计算实际胸环靶图中心点在模拟静态胸环靶图上的坐标
        int staticCenterX = (int) (scaleFactor * relativeX);
        int staticCenterY = (int) (scaleFactor * relativeY);

        LogUtil.error("main 标注点 x:" + staticCenterX + "   y：" + staticCenterY);
        //标注点
        bitmap = drawCircle(bitmap, staticCenterX, staticCenterY, isLastPoint);
        return bitmap;
    }

    private static Bitmap drawCircle(Bitmap image, int centerX, int centerY, boolean isLastPoint) {
        Canvas canvas = new Canvas(image);
        Paint paint = new Paint();
        // 启用抗锯齿
        paint.setAntiAlias(true);
        if (isLastPoint) { //最后一个点绘制为绿色
            paint.setColor(Color.GREEN);
        } else {
            paint.setColor(Color.RED);
        }
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(8f);
        int circleRadius = 13;
        canvas.drawCircle(centerX, centerY, circleRadius, paint);
        if (isLastPoint) { //最后一个点绘制为绿色
            paint.setColor(Color.RED);
        } else {
            paint.setColor(Color.BLUE);
        }
        paint.setStyle(Paint.Style.FILL);
        canvas.drawCircle(centerX, centerY, (circleRadius - 4), paint);
        return image;
    }
}
